package com.mvc.business.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.mvc.business.model.SampleItem;
import com.mvc.framework.model.Auditable;
import com.mvc.framework.service.BaseService;

/** 
 * 
 * @author  snowpbx
 * @version V1.0  Create Time: 2012-12-2
 */
@Service
public class SampleItemManager extends BaseService<SampleItem, Integer> {

	public List<SampleItem> getSampleItemsBySampleId(int sampleId) {
		SampleItem orderItem = new SampleItem();
		orderItem.setSampleId(sampleId);
		orderItem.setRecStatus(Auditable.REC_STATUS_VALID);
		return getHibernateTemplate().findByExample(orderItem);
	}

	public void deleteByOrderId(int sampleId) {
		deleteByWhere("sampleId=" + sampleId);
	}

	public void saveSampleItem(SampleItem orderItem, String operation) throws Exception {
		if (operation.equals("del")) {
			super.delete(orderItem.getId());
		} else if (operation.equals("add")) {
			orderItem.setId(null);
			super.save(orderItem);
		} else if (operation.equals("edit")) {
			super.save(orderItem);
		}
	}
}


